package com.example.yuejianapp14.Activity.Model;

import com.example.yuejianapp14.Activity.JavaBean.Success;
import com.example.yuejianapp14.Activity.JavaBean.User;
import com.example.yuejianapp14.Activity.Listener.ClubNoListListener;
import com.example.yuejianapp14.Activity.Listener.ListListener;
import com.example.yuejianapp14.Activity.Servics.UserService;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by jason_lin on 2017/9/25.
 */

public class UserModel {
    private Retrofit retrofit;
    private String BASEURL ="http://10.0.2.2/YueJian/index.php/Api/User/";
    private String HeadPhotoNameDefault="user_headphoto.png";

    public UserModel(){
        retrofit= new Retrofit.Builder()
                .baseUrl(BASEURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    public void updateuser(String uid,String uname,String uphone,String upassword,String uaddress,String uinfo,final ListListener<Success> listener){
        UserService userService=retrofit.create(UserService.class);
        Call<Success> call= userService.updateUserinfo(uid,uname,uphone,upassword,uaddress,uinfo);
        call.enqueue(new Callback<Success>() {
            @Override
            public void onResponse(Call<Success> call, Response<Success> response) {
                if (response.isSuccessful() && response.body() != null) {
                    listener.onResponse(response.body());
                }else
                    listener.onFail("onresponse fail");
            }

            @Override
            public void onFailure(Call<Success> call, Throwable t) {
                listener.onFail(t.toString());
            }
        });
    }

    public void findUserinfo(String uid,final ClubNoListListener listener) {
        UserService userService=retrofit.create(UserService.class);
        Call<User> call= userService.findUserinfo(uid);
        call.enqueue(new Callback<User>() {
            @Override
            public void onResponse(Call<User> call, Response<User> response) {
                if (response.isSuccessful() && response.body() != null) {
                    listener.onResponse(response.body());
                }else
                    listener.onFail("onresponse fail");

            }

            @Override
            public void onFailure(Call<User> call, Throwable t) {
                listener.onFail(t.toString());

            }
        });
    }
}
